﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using TfsComLib.TfsBranchLib2;
using WpfAdvControls.WpfConverters;

namespace TfsBranchLib2.View
{
    /// <summary>
    ///     Interaction logic for SourceControlFilterBox.xaml
    /// </summary>
    public partial class SourceControlFilterBox : UserControl
    {
        private ISourceControlFilter sourceControlFilter;

        public SourceControlFilterBox()
        {
            InitializeComponent();
        }

        public SourceControlFilterBox(ISourceControlFilter sourceControlFilter) : this()
        {
            SetBinding(sourceControlFilter);
        }

        public void SetBinding(ISourceControlFilter sourceControlFilter)
        {
            this.sourceControlFilter = sourceControlFilter;
            basepath.DataContext = this.sourceControlFilter;
            basepath.SetBinding(TextBox.TextProperty, new Binding("BasePath.BasePath") {Mode = BindingMode.OneWay});
            subpaths.DataContext = this.sourceControlFilter;
            subpaths.SetBinding(TextBox.TextProperty,
                new Binding("SubPathList")
                {
                    Converter = new ObservableCollectionToStringConverter(),
                    Mode = BindingMode.OneWay
                });
        }

        private void ButtonEditFilterClick(object sender, RoutedEventArgs e)
        {
            var popupWindow = new SourceControlFilterEditPopup(sourceControlFilter);
            popupWindow.ShowDialog();
        }
    }
}